import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { EquipVO, EquipForm, EquipQuery } from '@/api/hardware/equip/types';

/**
 * 查询设备列表
 * @param query
 * @returns {*}
 */

export const listEquip = (query?: EquipQuery): AxiosPromise<EquipVO[]> => {
  return request({
    url: '/hardware/equip/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询设备详细
 * @param id
 */
export const getEquip = (id: string | number): AxiosPromise<EquipVO> => {
  return request({
    url: '/hardware/equip/' + id,
    method: 'get'
  });
};

/**
 * 新增设备
 * @param data
 */
export const addEquip = (data: EquipForm) => {
  return request({
    url: '/hardware/equip',
    method: 'post',
    data: data
  });
};

/**
 * 修改设备
 * @param data
 */
export const updateEquip = (data: EquipForm) => {
  return request({
    url: '/hardware/equip',
    method: 'put',
    data: data
  });
};

/**
 * 删除设备
 * @param id
 */
export const delEquip = (id: string | number | Array<string | number>) => {
  return request({
    url: '/hardware/equip/' + id,
    method: 'delete'
  });
};

export const activeEquip = (ids: string | number | Array<string | number>) => {
  console.log(ids);
  return request({
    url: '/hardware/equip/active/' + ids,
    method: 'put'
  });
};

/**
 * 设备状态修改
 */
export const changeEquipRunStatus = (id: string | number, status: number) => {
  const data = {
    id,
    status
  };
  return request({
    url: '/hardware/equip/changeRunStatus',
    method: 'put',
    data: data
  });
};
